<!DOCTYPE html>
<html class="x-admin-sm">

<head>
	<meta charset="UTF-8">
	<title>电子学会比赛管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
	<link rel="stylesheet" href="./css/font.css">
	<link rel="stylesheet" href="./css/common.css">
	<link rel="stylesheet" href="./css/xadmin.css">
	<script type="text/javascript" src="./js/abkj/match/api/news.js"></script>
	<script type="text/javascript" src="./js/abkj/fun_tool.js"></script>
	<script type="text/javascript" src="./js/abkj/slAjax.js"></script>
	<script src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>
</head>

<body>
<div class="x-nav">
	<span class="layui-breadcrumb">
			<a href="">首页</a>
			<a><cite>网站配置</cite></a>
			<a><cite>信息配置</cite></a>
	</span>
	<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
		<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
	</a>
</div>
<div class="layui-fluid">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">
			<div class="layui-card" id="content" v-cloak>
				<div class="layui-card-header">
					<!--<button class="layui-btn layui-btn-danger" onclick="delAll()">-->
						<!--<i class="layui-icon"></i>批量删除-->
					<!--</button>-->
					<button class="layui-btn" v-on:click="addNews">
						<i class="layui-icon"></i>添加
					</button>
				</div>
				<div class="layui-card-body ">
					<table class="layui-table layui-form" id="table">
						<span>共计{{total}}条数据</span>
					</table>
					<section id="page"></section>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<script src="./js/jquery.min.js"></script>
<script type="text/html" id="operating">
<a href="javascript:;" class="layui-table-link" onclick=app.up2Top('{{d.id}}')>置顶</a>
<a href="javascript:;" onclick="xadmin.open('编辑','editInformation.html?id='+{{d.id}})" class="layui-table-link">编辑</a>
<a href="javascript:;" class="layui-table-link" onclick=app.remove('{{d.id}}')>删除</a>
</script>
<script src="./js/vue.js"></script>
<script>
	var app=new Vue({
		el: '#content',
		data: {
			newsList:[],// 新闻列表
			list:[], // 表格初始化数据
			total: 0,
			pageNo: 1,
			pageSize: 50,
			status:['审核','待审核' ,'通过', '不通过'],
			participate:['审核','参赛' ,'弃权' ],
			cols: [ //表头
				{field: 'index', title: '序号'},
				{field: 'title', title: '标题'},
				{field: 'modelName', title: '模块'},
				{field: 'createTime', title: '上传日期'},
				{field: 'operating', title: '操作', width: 135, templet: '#operating'},
			]
		},
		methods:{
			opentab:function(name,url){
				//单击事件
				console.log(name)
				console.log(url)
				xadmin.add_tab(name,url)
			},
			remove: function (id) {

				layer.confirm('确认删除吗？', function () {
					NewsdelObj(id,function(data){
					    //删除成功
						layer.msg('删除成功!', {icon: 1})
						app.loadNewsList()
						app.init()
					})
				})
			},
			addNews:function(){
				xadmin.open('添加信息','editInformation.html')
			},
			up2Top:function(varNewsId){// 置顶
				var queryData = {
				    page:{
				        current:1, //当前页数
				        size: 1  //每页长度
				    },
				    cond:{ //条件
				        eq:{ // 多条件对象
				        	modelName:'新闻'
	                    },
	                    order:{ //排序条件
	                    	type:"desc",
	                    	attrName:["sort_id","create_time"]
	                    }
				    }
				};
				NewsPageList(queryData,function(data){
					// 找到当前置顶的新闻
					app.newsList=data;
					var retList = data.records;
					if(retList.length > 0){
						var newSortId = retList[0].sortId+1;//当前最大数值+1
						var updateParam={
							id:varNewsId,
							sortId:newSortId
						}
						NewsupdateById(updateParam,function(data){
							// 更新成功，
						},function(status,message){
							// 置顶更新失败
						})
					}
				},function(status,message){

				})
			},
			loadNewsList:function(){ //加载新闻数据
				var vm = this
				var queryData = {
				    page:{
				        current: vm.pageNo, //当前页数
				        size: vm.pageSize  //每页长度
				    },
				    cond:{ //条件
				        eq:{ // 多条件对象
	                    }
	                    ,
	                    order:{ //排序条件
	                    	type:"desc",
	                    	attrName:["sort_id","create_time"]
	                    }
				    }
				};
				NewsPageList(queryData,function(data){
					app.newsList=data;
					app.list = []
					app.total = data.total
					var retList = data.records;
					for(var i=0; i<retList.length; ++i){
						var itemNews = {
							index:i+(data.current-1)*data.size,
							id:retList[i].id,
							title:retList[i].title,
							createTime:retList[i].createTime,
							bannerImg:retList[i].bannerImg,
							modelName:retList[i].modelName
						}
						app.list.push(itemNews);
					}
				},function(status,message){

				})
			},
			getData(){
				this.loadNewsList();
				this.init()
			},
			init:function() {
				var that = this
				var vm = this
				layui.use(['laypage','table'], function () {
					// var laypage = layui.laypage;
					// //执行一个laypage实例
					// laypage.render({
					// 	elem: 'test1' //注意，这里的 test1 是 ID，不用加 # 号
					// 	,count: 16 //数据总数，从服务端得到
					// });
					var table = layui.table
					//头工具栏事件
					table.render({
						elem: '#table',
						title: '用户数据表',
						cols: [that.cols],
						data: that.list,
						count:app.newsList.total
					})
					layui.laypage.render({
						elem: 'page',
						count: vm.total,
						pageSize: vm.pageSize,
						curr: vm.pageNo,
						jump: function (obj, first) {
							if (first) return
							vm.pageNo = obj.curr
							vm.init()
							vm.loadNewsList();
						}
					})
				})
			}
		}
	})
	window.onload=function(){
		app.getData()
	}
</script>
<script>
	// $(function () {
	// 	layui.use(['form', 'table'], function () {
	// 		var form = layui.form
	// 		// layer.msg('玩命卖萌中', function(){
	// 		//   //关闭后的操作
	// 		//   });
	// 		//监听提交
	// 		form.on('submit(sreach)', function (data) {
	// 			console.log(data)
	// 			// layer.msg(JSON.stringify(data.field), function () {
	// 			// location.href = 'index.html'
	// 			// })
	// 			return false
	// 		})

	// 		var table = layui.table
	// 		table.render({
	// 			elem: '#table',
	// 			height: 500,
	// 			url: '', //数据接口
	// 			page: true, //开启分页
	// 			cols: app.data.cols,
	// 			data: app.data.list
	// 		})
	// 	})


	// })
</script>

</html>
